package com.southwind.springboottest.study.注解事件处理器;

/**
 * @description：TODO
 * @author： HXG
 * @create： 2023/12/18 17:45
 */

import javax.swing.*;
import java.awt.*;

/**
 * For annotation test
 */
public class ButtonTest {
    public static void main(String[] args) {
        ButtonFrame btnFrame = new ButtonFrame();
        btnFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        btnFrame.setVisible(true);
    }
    static class ButtonFrame extends JFrame {
        private JPanel panel;
        private JButton yellowBtn;
        private JButton blueBtn;
        private JButton redBtn;
        public ButtonFrame() {
            setTitle("ButtonTest");
            setSize(300, 200);
            panel = new JPanel();
            add(panel);
            yellowBtn = new JButton("Yellow");
            blueBtn = new JButton("blue");
            redBtn = new JButton("red");
            panel.add(yellowBtn);
            panel.add(blueBtn);
            panel.add(redBtn);
            ActionListenerInstaller.processAnnotations(this);
        }
        @ActionListenerFor(source = "yellowBtn", level = 1)
        public void yellowBg() {
            panel.setBackground(Color.YELLOW);
        }
        @ActionListenerFor(level = 2, source = "blueBtn")
        public void blueBg() {
            panel.setBackground(Color.BLUE);
        }
        @ActionListenerFor(source = "redBtn")
        public void redBg() {
            panel.setBackground(Color.RED);
        }
    }
}
